/*
 * StaticCLib.h
 *
 *  Created on: Oct 29, 2011
 *      Author: Rui Zhuang && Heqing Huang
 */

#ifndef STATICCLIB_H_
#define STATICCLIB_H_

#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>

#define bool int
#define true 1
#define false 0

//import sjc.annotation.NonNullElements;
//import sjc.util.Util;

/**
 * The StaticJava Library.
 *
 * @author <a href="mailto:robby@cis.ksu.edu">Robby</a>
 */
//public class StaticJavaLib {
//  /**
//   * Asserts a given value to be true.
//   *
//   * @param b
//   *          The boolean value to assert.
//   */
//  public static void assertTrue(final boolean b) {
//    assert b;
//  }

void StaticJavaLib_assertTrue(bool b)
{
  assert(b);
}


  /**
   * Returns the boolean value of a string from a string array
   *
   * @param args
   *          The string array. Must be non-null.
   * @param i
   *          The index of the string in the string array. The value of i must
   *          be equal or greater than 0, and less than the length of the string
   *          array.
   * @return The boolean value of args[i]
   */
//  public static boolean getBooleanArgument(
//      @NonNullElements final String[] args, final int i) {
//    assert Util.checkNonNullElements(args) && (i >= 0) && (i < args.length);
//    return Boolean.valueOf(args[i]).booleanValue();
//  }

bool StaticJavaLib_getBooleanArg(char** args, int length, int i) {

  assert(args!=NULL && i>=0 && i<length);
  if(!strcmp(args[i],"true"))
       return true;
  if(!strcmp(args[i],"false"))
       return false;

}

  /**
   * Returns the int value of a string from a string array
   *
   * @param args
   *          The string array.
   * @param i
   *          The index of the string in the string array. The value of i must
   *          be equal or greater than 0, and less than the length of the string
   *          array.
   * @return The int value of args[i]
   */
//  public static int getIntArgument(@NonNullElements final String[] args,
//      final int i) {
//    assert Util.checkNonNullElements(args) && (i >= 0) && (i < args.length);
//    return Integer.parseInt(args[i]);
//  }

int StaticJavaLib_getIntArg(char** args,int length, int i)
{
    //no way to get the size of the array
   assert(args!=NULL && i>=0 && i<length);
   return atoi(args[i]);
}


  /**
   * Prints a boolean value to the standard console output.
   *
   * @param b
   *          The boolean value to print.
   */
//  public static void print(final boolean b) {
//    System.out.print(b);
//    System.out.flush();
//  }

void StaticJavaLib_printb(bool i)
{
  if (i==0)
    printf("%s","fool");
  else
    printf("%s", "true");
}

  /**
   * Prints an int value to the standard console output.
   *
   * @param i
   *          The integer to print.
   */
//  public static void print(final int i) {
//    System.out.print(i);
//    System.out.flush();
//  }
void StaticJavaLib_printi(int i)
{
    printf("%d",i);
}

  /**
   * Prints a new line to the standard console output.
   */


void StaticJavaLib_println()
{
    printf("\n");
}

  /**
   * Prints a boolean value and a new line to the standard console output.
   *
   * @param b
   *          The boolean value to print.
   */
//  public static void println(final boolean b) {
//    System.out.println(b);
//    System.out.flush();
//  }

void StaticJavaLib_printlnb(bool i)
{
  if (i==0)
    printf("%s\n","fool");
  else
    printf("%s\n", "true");
}


  /**
   * Prints an int value and a new line to the standard console output.
   *
   * @param i
   *          The integer to print.
   */
//  public static void println(final int i) {
//    System.out.println(i);
//    System.out.flush();
//  }

void StaticJavaLib_printlni(int i)
{
    printf("%d\n",i);
}


}




#endif /* STATICCLIB_H_ */
